<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>数组相对排序</title>
</head>
<body>
  <script>
    function fn(arr1, arr2) {
      let arr = []
      for (let i = 0; i < arr2.length; i++) {
        for (let j = 0; j < arr1.length; j++) {
          if (arr2[i] === arr1[j]) {
            arr.push(arr1[j])
          }
        }
      }
      arr.push(...arr1.filter(i => arr.indexOf(i) == -1).sort((a, b) => a - b))
      return arr
    }
    console.log(fn([2, 3, 1, 3, 2, 4, 6, 7, 9, 2, 19], [2, 1, 4, 3, 9, 6]))
  </script>
</body>
</html>